window.gameData = null;

window._GAMEDATAHELPER = {

    itemArrTypeConfig:[
        //战斗道具数组
        'fightItem',
        //装备道具数组
        'equipItem',
        //材料道具数组
        'materialItem',
        //技能道具数组
        'skillItem',
    ],

    //f--友好度 die--死亡标记 
    //zm--招募标记 gy--雇佣标记 diq--调遣标记
    //dq--盗窃标志 qz--敲诈标记 sh--索贿标记
    //country--所属
    //sign-- 是否解锁
    _defaultNpcLog:{country:null,city:null,f:0,die:0,zm:0,dq:0,qz:0,sh:0,diq:0,gy:0,sign:false},

    
     addNoFightStep:function(nmb){

        if(window.gameData.noFightStep){
            window.gameData.noFightStep+=nmb;
        }else{
            window.gameData.noFightStep=nmb;
        }

        _TIPS.showMessage(window.gameData.noFightStep+"步之内不遇敌");
    },

    reduceFightStep:function(){
        if(window.gameData.noFightStep){
            window.gameData.noFightStep--;
            return true;
        }else{
            return false;
        }
    },


    //功利升级商店等级
    getShopLevelBySelect:function(){
        var selectValue = _GAMEDATAHELPER.getSelectValue();
        var MaxLevel = Math.floor(selectValue['gongli']/100);
        return MaxLevel;
    },

    //信仰升级宝箱奖励
    getBoxNmbBySelect:function(){
        var selectValue = _GAMEDATAHELPER.getSelectValue();
        var MaxLevel = Math.floor(selectValue['xinyang']/100);
        return MaxLevel;
    },

    //自由升级售出比例
    getSellPerBySelect:function(){
        var selectValue = _GAMEDATAHELPER.getSelectValue();
        if(selectValue['ziyou']==100){
            return 0.05;
        }else if(selectValue['ziyou']==200){
            return 0.1;
        }else if(selectValue['ziyou']==300){
            return 0.2;
        }else if(selectValue['ziyou']==400){
            return 0.3;
        }else if(selectValue['ziyou']==500){
            return 0.4;
        }else if(selectValue['ziyou']==600){
            return 0.5;
        }
        return 0;
    },

    getSelectValue:function(){

        if(!window.gameData.selectValueMap){
            window.gameData.selectValueMap={
                ziyou:0,
                gongli:0,
                xinyang:0
            }
        }

        return window.gameData.selectValueMap;

    },

    setSelectValue:function(key,value){

        var selectValueMap = _GAMEDATAHELPER.getSelectValue();
        selectValueMap[key]+=value;
        if(
            //key!='ziyou'&&
            selectValueMap.xinyang==selectValueMap.gongli
        ){
            selectValueMap.ziyou+=100;
        }

    },


    switchArmy:function(){
        if(window.gameData.closeArmy==1){
            window.gameData.closeArmy=2;
        }else{
            window.gameData.closeArmy=1;
        }
    },

    isArmy:function(){
        if(!window.gameData.closeArmy){
            window.gameData.closeArmy=1;
        }
        return window.gameData.closeArmy==1;
    },


    getSaveMap:function(){

        if(!window.gameData.saveMap){
            window.gameData.saveMap = '山寨'
        }

        return window.gameData.saveMap;
    },

    setSaveMap:function(map){

        window.gameData.saveMap = map;

    },

    getTzLog:function(tzindex){

        if(!window.gameData.xyjtzLog){
            window.gameData.xyjtzLog={};
        }
        
        if(window.gameData.xyjtzLog[tzindex]){
            return true;
        }

        return false;

    },

    setTzLog:function(tzindex){

        if(!window.gameData.xyjtzLog){
            window.gameData.xyjtzLog={};
        }

        window.gameData.xyjtzLog[tzindex]=1;
    },


    getTzTeam:function(tzindex){

        if(!window.gameData.tzTeam){
            window.gameData.tzTeam={};
        }

        return window.gameData.tzTeam[tzindex];
    },

    setTzTeam:function(tzindex,team){
        if(!window.gameData.tzTeam){
            window.gameData.tzTeam={};
        }

        window.gameData.tzTeam[tzindex]=_CU.cloneObj(team);
    },

    openAllNpc:function(){

        for(var key in _NPC){

            _GAMEDATAHELPER.signNpcTj(key);

        }

        
        for(var key in _EQUIP){
            _GAMEDATAHELPER.signNpcTj(key);
        }

        for(var key in _SKILLBD){
            _GAMEDATAHELPER.signNpcTj(key);
        }

        for(var key in _SKILL){
            _GAMEDATAHELPER.signNpcTj(key);
        }

        /*
        for(var key in _XW){
            _GAMEDATAHELPER.signNpcTj(key);
        }
            */

        for(var key in _FIGHTITEM){
            _GAMEDATAHELPER.signNpcTj(key);
        }


        for(var key in _JOB){
            _GAMEDATAHELPER.signNpcTj(key);
        }

        for(var key in _DICT){
            _GAMEDATAHELPER.signNpcTj(_DICT[key]);
        }

        for(var key in _STATUSCONFCHESS){
            _GAMEDATAHELPER.signNpcTj(_STATUSCONFCHESS[key].name);
        }


        for(var key in _XW){
            _GAMEDATAHELPER.signNpcTj(_XW[key].label);
        }

        
    },


    hasNpcTj:function(npcname){
        if(
            window.gameData.npctj
            &&window.gameData.npctj[npcname]
        ){
            return true;
        }

        return false;
    },

    signXwTjByRole:function(role){
        var xwobj = null;
        if(role.xwlevel){
            xwobj=role.xwlevel;
        }else if(role.npctype&&_NPC[role.npctype]){
            xwobj=_NPC[role.npctype].npcxw;
        }

        for(var key in xwobj){
            _GAMEDATAHELPER.signNpcTj(_XW[key].label);
        }
    },

    signNpcTj:function(npcname){

        if(!window.gameData.npctj){
            window.gameData.npctj={};
        }

        window.gameData.npctj[npcname]=1;
    },


    //获取商店等级
    getShopLevel:function(shop){
        if(!window.gameData.shopLevel){
            window.gameData.shopLevel={};
        }
        if(window.gameData.shopLevel[shop]){
            return window.gameData.shopLevel[shop];
        }
        return 0;
    },

    //升级商店
    upShopLevel:function(shop){
        if(!window.gameData.shopLevel){
            window.gameData.shopLevel={};
        }

        var nextlevel = 1;

        if(window.gameData.shopLevel[shop]){
            nextlevel = window.gameData.shopLevel[shop]+1;
        }

        var cutwood = _MSHOP._WOODNMB;

        //if(_GAMEDATAHELPER.oprWood(-cutwood)){
            if(_GAMEDATAHELPER.oprMoney(-cutwood)){
            window.gameData.shopLevel[shop] = nextlevel;
            return true;
        }else{
            return false;
        }
    },

    //判定关卡成就是否可以完成
    getChapterCjEnable:function(chapter,lv){

        return false;
    },

    //获取关卡成就完成状态
    getChapterCj:function(chapter,lv){
        if(!window.gameData.chapterCj){
            window.gameData.chapterCj={};
        }

        return window.gameData.chapterCj[chapter+"-"+lv];
    },

    //标记关卡成就完成状态
    signChapterCj:function(chapter,lv){
        if(!window.gameData.chapterCj){
            window.gameData.chapterCj={};
        }

        if(window.gameData.chapterCj[chapter+"-"+lv]){
            return false;
        }

        window.gameData.chapterCj[chapter+"-"+lv]=1;
        return true;
    },


    openAllChapter:function(){

        for(var key in _MAPCONFIG){

            _GAMEDATAHELPER.openChapter(key);

        }

    },


    openChapter:function(chapter){
        if(window.gameData.openChapter){
            window.gameData.openChapter[chapter]=1;
        }else{
            window.gameData.openChapter={};
            window.gameData.openChapter[chapter]=1;
        }
    },

    isChapterOpen:function(chapter){
        if(window.gameData.openChapter){
             if(window.gameData.openChapter[chapter]){
                return true;
             }
             if(_MAPCONFIG[chapter]&&_MAPCONFIG[chapter].premap){
                var openall = true;
                for(var i=0;i<_MAPCONFIG[chapter].premap.length;i++){
                    if(!window.gameData.openChapter[_MAPCONFIG[chapter].premap[i]]){
                        openall=false;
                    }
                }
                return openall;
             }
        }
        return false;
    },

    //获取制作次数上限
    getMakeMax:function(){

        if(_GAMEDATAHELPER.hasTeamSkill('qiaojiang')){

            return _HDLVHELPER.getAttrByHdLv('makeMax');

        }

        return 1;
    },

    //判断是否二周目
    isSecondPart:function(){

        if(window.gameData.passType){
            return true;
        }else{
            return false;
        }

    },

	//剧情是否已经触发
	isLogStory:function(story){
		
		if(window.gameData){
			
			if(window.gameData.storyLog){
				
				return window.gameData.storyLog[story];
				
			}
			
		}
		
		return false;
		
	},
	
	//记录剧情
	logStory:function(story){
		
		if(window.gameData){
			
			if(!window.gameData.storyLog){
				
				window.gameData.storyLog={};
				
			}
			
			window.gameData.storyLog[story]=1;
			
		}
		
	},


    getPlayerLv:function(){
        return _EXPMANAGER.getLevelByExp(window.gameData.playerTeam[0].exp);
    },

    getTeamLv:function(){
        
        var teamlv = 0;
        for(var i=0;i<window.gameData.playerTeam.length;i++){
            var tmplv = _EXPMANAGER.getLevelByExp(window.gameData.playerTeam[i].exp);
            if(teamlv<tmplv){
                teamlv = tmplv;
            }
        }
        return teamlv;
        
       //return _EXPMANAGER.getLevelByExp(window.gameData.playerTeam[0].exp);
    },

    isBossKill:function(map,x,y){
        var key = map+"-"+x+"-"+y
        if(!window.gameData.bossKillLog){
            window.gameData.bossKillLog={};
        }
        return window.gameData.bossKillLog[key];
    },

    killBossSign:function(map,x,y){
        var key = map+"-"+x+"-"+y
        if(!window.gameData.bossKillLog){
            window.gameData.bossKillLog={};
        }
        window.gameData.bossKillLog[key]=1;
    },

    eatpeople:function(){

        var randomlv = _CU.randomObj(_CS.fivedata);
        if(
            window.gameData
            &&window.gameData.playerTeam
            &&window.gameData.playerTeam[0]
            &&window.gameData.playerTeam[0][randomlv]
        ){
            window.gameData.playerTeam[0][randomlv]++;

            return window.gameData.playerTeam[0].name+"'"+_CS.fivedataStr[randomlv]+"'上升1点";
        }
        return null;
    },

    isMapSign:function(map){

        if(!window.gameData.mapSignLog){
            window.gameData.mapSignLog={};
        }

        return window.gameData.mapSignLog[map];

    },

    //点亮地图
    signMap:function(map){

        if(!window.gameData.mapSignLog){
            window.gameData.mapSignLog={};
        }

        if(!window.gameData.mapSignLog[map]){
            _GAMEDATAHELPER.addLevelData('levelBright',2);
            window.gameData.mapSignLog[map]=1; 
        }

    },

    addLevelData:function(attr,data){
        if(!window.gameData[attr]){
            window.gameData[attr]=0;
        }
        var olddata = window.gameData[attr];

        if(attr=='levelFight'&&window.gameData.master){

            var npcConf = _NPC[window.gameData.master];
            var zxlevel = npcConf.title?_HONOUR._EXP[npcConf.title]:0;
            if((window.gameData[attr]+data)<=zxlevel){
                window.gameData[attr]+=data;
            }else if(window.gameData[attr]<zxlevel){
                window.gameData[attr]=zxlevel;
            }

        }else{

            window.gameData[attr]+=data;
            if(window.gameData[attr]<0){
                window.gameData[attr]=0;
            }else if(window.gameData[attr]>_HONOUR._EXPMAX){
                window.gameData[attr]=_HONOUR._EXPMAX;
            }

        }

        
        if(window.gameData[attr]!=olddata){
            if(window._MAP){
                window._MAP.refreshRoleInfo();
            }
            return true;
        }else{
            return false;
        }
    },

    isNpcMaster:function(npc){

        var npclog = _GAMEDATAHELPER.getNpcLog(npc);
        if(npclog){
            var country = npclog.country;
            if(country){
                var masterConf = _MASTER[country];
                if(masterConf){
                    return masterConf.boss == npc;
                }
            }
        }

        return false;

    },

    backCityhp:function(){

        for(var i=0;i<window.gameData.playerTeam.length;i++){
            var player = window.gameData.playerTeam[i];
            var playerData = _ROLEDATA.getRoleDataOfPlayer(player);
            player.hp = playerData.maxHp;
            player.mg = playerData.maxMagic;
        }

        for(var i=0;i<window.gameData.playerTeamBack.length;i++){
            var player = window.gameData.playerTeamBack[i];
            var playerData = _ROLEDATA.getRoleDataOfPlayer(player);
            player.hp = playerData.maxHp;
            player.mg = playerData.maxMagic;
        }

    },


    //npc能否出现在战斗中
    canNpcFight:function(name){

        var npclog = _GAMEDATAHELPER.getNpcLog(name);
        var playerCountry = window.gameData.country;

        if(npclog){

            //阵亡 被招募 被雇佣 被调遣都无法出现在战斗中
            if(
                npclog.die
                ||npclog.zm
                ||npclog.gy
                ||npclog.diq
            ){
                return false;
            }else{

                //同阵营无法出现在战斗中
                if(playerCountry!=null&&playerCountry==npclog.country){
                    return false;
                }

            }

        }

        return true;

    },


    getNpcLog:function(name){
        if(window.gameData.realPos[name]){
            return window.gameData.realPos[name];
        }else {
            var orignpc = _ODATAHELPER.getNpcLog(name);
            if(orignpc){
                window.gameData.realPos[name]=orignpc;
            }
            return orignpc;
        }
    },

    addNpcF:function(name,f){

       
        var npclog = _GAMEDATAHELPER.getNpcLog(name);

        var oldf = npclog.f;

        if(npclog){
            npclog.sign=1;
            npclog.f+=f;
            if(npclog.f>100){
                npclog.f=100;
            }
            //console.log('好友度提升:',name,f,oldf,npclog.f);
        }
    },

    getInitData:function(roleData){

        return {
            fightSpeed:1,//战斗速度
            lastx:null,//跳转前x坐标
            lasty:null,//跳转前y坐标
            lastmap:null,//跳转前地图
            targetPoint:_CS.beginPoint,//目标坐标点
            defaultMap:_CS.beginMap,//默认地图
            isPlayAudio:true,//是否播放音乐
            gold:100000,//金钱
            wood:0,//木头
            levelBright:0,//名声
            levelDark:0,//恶名
            levelFight:0,//功勋
            country:null,//势力
            master:null,//直系上司
            isMaster:false,//是否主公
            countryFlag:false,//贼&官
            //上阵队员
            playerTeam:[roleData],
            //替补
            playerTeamBack:[],
            //战斗道具数组
            fightItem:[],
            //装备道具数组
            equipItem:[],
            //碎片数组
            materialItem:[],
            //技能道具数组
            skillItem:[],
            //特殊道具数组
            specilItem:[],
            //任务列表
            workList:[],
            //军团技能
            teamSkill:[],
            //人物记录
            realPos:{},
            //药物记录
            itemEffect:{},
            //城市归属
            cityLog:{},
            //技能获取日志
            skillLog:{},
            //成就日志
            cjLog:{},
            //小兵初始属性
            armybaseAttr:10,
            targetPoint:"游戏开始",//目标坐标点
            defaultMap:'如意画卷'
        }
    },

    getCjLog:function(){

        if(!window.gameData.cjLog){
            window.gameData.cjLog = {};
        }

        return window.gameData.cjLog;
    },

    hasGetCj:function(key){
        var cjlog = _GAMEDATAHELPER.getCjLog();
        return cjlog[key]?true:false;
    },

    signCjLog:function(key){

        var cjlog = _GAMEDATAHELPER.getCjLog();
        cjlog[key]=1;
    },

    logBox:function(city,x,y){

        if(!window.gameData.boxLog){
            window.gameData.boxLog={};
        }

        window.gameData.boxLog[city+"-"+x+"-"+y]=1;

    },

    isBoxLoged:function(city,x,y){
        if(!window.gameData.boxLog){
            window.gameData.boxLog={};
        }
        return  window.gameData.boxLog[city+"-"+x+"-"+y];
    },

    canStudy:function(npc){

        var npclog = _GAMEDATAHELPER.getNpcLog(npc);
        if(npclog&&npclog.f>=_MANAGERROLELABEL.getFuncValueOfType('学艺')){
            return true;
        }

        return false;

    },

    
    
    getEnableSkillOfNpc:function(npc){

        if(_NPC[npc]&&_NPC[npc].skill){

            var result = [];

            for(var i=0;i<_NPC[npc].skill.length;i++){
                var skillname = _NPC[npc].skill[i];
                var skillConf = _SKILL[skillname]?_SKILL[skillname]:_SKILLBD[skillname];
                if(skillConf&&!skillConf.only&&!skillConf.exc){
                    result.push(skillname);
                }else{
                    if(
                        window.gameData
                        &&window.gameData.skillLog
                        &&window.gameData.skillLog[skillname]
                    ){

                    }else{
                        result.push(skillname);
                    }
                }
            }

            //console.log('学艺池:',result);

            return result;
        }

        return null;

    },


    getNpcRelationType:function(npcname){

        var npclog = _GAMEDATAHELPER.getNpcLog(npcname);
        var playerCountry = window.gameData.country;
        if(playerCountry==null
            ||npclog.country=="中立"
            ||_MASTERHELPER.isCountryOver(npclog.country))
        {
            return _MPEOPLE._ARRTYPEMIDDLE;
        }else if(npclog.country==playerCountry){
            return _MPEOPLE._ARRTYPEFRIEND;
        }else{
            return _MPEOPLE._ARRTYPEARMY;
        }

    },


    getNpcByType:function(type){

        var result = [];
        for(var key in window.gameData.realPos){
            var npclog = window.gameData.realPos[key];
            if(npclog.sign
                &&!npclog.die
                &&!npclog.diq
                &&!npclog.gy
                &&!npclog.zm
                ){
                var npcRelationType = _GAMEDATAHELPER.getNpcRelationType(key);
                if(type==npcRelationType){
                    result.push(key);
                }
            }
        }
        return result;

    },


    getMaxLengthOfPlayerTeam(){
        return 5;
    },

    //使用道具1个
    reduceItemByName:function(goodsName){

        var goodsIndex = _GAMEDATAHELPER.getUnlockGoodsIndex(window.gameData.specilItem,goodsName);
        if(
            goodsIndex!=-1
            &&_GAMEDATAHELPER.reduceGoods(window.gameData.specilItem,goodsIndex,1)
        ){
            return true;
        }

        goodsIndex = _GAMEDATAHELPER.getUnlockGoodsIndex(window.gameData.fightItem,goodsName);
        if(
            goodsIndex!=-1
            &&_GAMEDATAHELPER.reduceGoods(window.gameData.fightItem,goodsIndex,1)
        ){
            return true;
        }
        return false;
    },

    //使用道具1个
    reduceSomeItemByName:function(goodsName,nmb){

      var goodsIndex = _GAMEDATAHELPER.getUnlockGoodsIndex(window.gameData.specilItem,goodsName);
      if(
          goodsIndex!=-1
          &&_GAMEDATAHELPER.reduceGoods(window.gameData.specilItem,goodsIndex,nmb)
      ){
          return true;
      }
      return false;
  },

    //消减道具
    reduceGoods:function(arr,index,nmb){

        if(nmb==0)
            return true;

        if(arr[index]){

            if(arr[index].nmb){
                if(arr[index].nmb>nmb){
                    arr[index].nmb-=nmb;
                }else if(arr[index].nmb==nmb){
                    arr.splice(index,1);
                }else{
                    return false;
                }
            }else{
                if(nmb==1){
                    arr.splice(index,1);
                }else{
                    return false;
                }
            }

            return true;

        }else{

            return false;
            
        }

        

    },

    //获取未上锁道具位置
    getUnlockGoodsIndex:function(arr,goodstype){

        if(arr){
            for(var i=0;i<arr.length;i++){
                if(arr[i].type == goodstype&&!arr[i].isLock){
                    return i;
                }
            }
        }
        return -1;
    },


    //获取道具位置
    getGoodsIndex:function(arr,goodstype){

        if(arr){
            for(var i=0;i<arr.length;i++){
                if(arr[i].type == goodstype){
                    return i;
                }
            }
        }
        return -1;
    },

    //获取道具数量
    getGoodsNmb:function(arr,goodstype){

        var goodsIndex = _GAMEDATAHELPER.getGoodsIndex(arr,goodstype);
        if(goodsIndex!=-1){
            var tempgood = arr[goodsIndex];
            if(tempgood.nmb){
                return tempgood.nmb;
            }else{
                return 1;
            }
        }
        return 0;
    },


    /*
    增加或者减去金额
    _GAMEDATAHELPER.oprMoney(100);
    _GAMEDATAHELPER.oprMoney(-100);
    */

    oprMoney:function(nmb){

        if(window.gameData.gold+nmb<0){
            return false;
        }else{
            window.gameData.gold+=nmb;
            if(window._MAP){
                window._MAP.refreshGoldInfo();
            }
            return true;
        }

    },

    oprWood:function(nmb){

        if(!window.gameData.wood){
            window.gameData.wood=0;
        }

        if(window.gameData.wood+nmb<0){
            return false;
        }else{
            window.gameData.wood+=nmb;
            if(window._MAP){
                window._MAP.refreshGoldInfo();
            }
            return true;
        }

    },

    //获取当前金额数
    getMoney:function(){
        if(window.gameData&&window.gameData.gold)
            return window.gameData.gold;
        return 0;
    },

    getWood:function(){
        if(window.gameData&&window.gameData.wood)
            return window.gameData.wood;
        return 0;
    },


    //获取主角信息
    getMainRoleInfo:function(){

        var title = (window.gameData.country&&_MASTER[window.gameData.country])?
                    _MASTER[window.gameData.country].name+".":"无势力";
        
        if(window.gameData.country){
            var titleIndex = _CU.getLevelOfArr(_HONOUR._EXP,window.gameData.levelFight);
            var countryFlag = _MASTER[window.gameData.country].flag;
            var titleName = countryFlag?_HONOUR._TITLE1[titleIndex]:_HONOUR._TITLE2[titleIndex];
            title+=titleName;
        }

        for(var i=0;i<window.gameData.playerTeam.length;i++){
            var playerRole=window.gameData.playerTeam[i];
            if(playerRole.isMainRole){
                return {
                    face:playerRole.face,
                    lv:_EXPMANAGER.getLevelByExp(playerRole.exp),
                    title:title
                }
            }

        }

        return null;
    },


    pushItemToArr:function(arr,obj){

        if(!arr||!obj)
            return ;
        var objnmb = obj.nmb?obj.nmb:1;

        for(var i=0;i<arr.length;i++){
            if(obj.type == arr[i].type){
                if(arr[i].nmb){
                    arr[i].nmb+=objnmb;
                }else{
                    arr[i].nmb=objnmb+1;
                }   
                return;
            }
        }

        arr.unshift(obj);
    },

    //往仓库新增道具
    pushItem:function(obj){

        if(
            window.gameData
            &&obj
            ){

            if(obj.objtype=="equip"){
                _GAMEDATAHELPER.signNpcTj(obj.type)
                window.gameData.equipItem.unshift(obj);
            }else if(obj.objtype=="fightitem"){
                _GAMEDATAHELPER.signNpcTj(obj.type)
                var itemConf = _FIGHTITEM[obj.type];

                if(itemConf.skilltype=="attack"){
                    _GAMEDATAHELPER.pushItemToArr(window.gameData.fightItem,obj);
                }else if(itemConf.skilltype=="bosspart"){
                    _GAMEDATAHELPER.pushItemToArr(window.gameData.materialItem,obj);
                }else{
                    _GAMEDATAHELPER.pushItemToArr(window.gameData.specilItem,obj);
                }


            }else if(obj.objtype=="material"){
                _GAMEDATAHELPER.pushItemToArr(window.gameData.materialItem,obj);
            }else if(obj.objtype=="skill"||obj.objtype=="skillbd"){
                _GAMEDATAHELPER.signNpcTj(obj.type)
                _GAMEDATAHELPER.pushItemToArr(window.gameData.skillItem,obj);
            }else if(obj.objtype=="teamskill"){
                _GAMEDATAHELPER.pushItemToArr(window.gameData.teamSkill,obj);
            }else{
                _GAMEDATAHELPER.pushItemToArr(window.gameData.specilItem,obj);
            }

        }

    },

    hasTeamSkill:function(sign){

        if(window.gameData
            &&window.gameData.teamSkill){

            for(var i=0;i<window.gameData.teamSkill.length;i++){
                var teamSkillConfig = _SKILLTEAM[window.gameData.teamSkill[i].type];
                if(teamSkillConfig&&teamSkillConfig.sign==sign){
                    return true;
                }
            }

        }

        return false;

    },


    getFightItemNmb:function(itemName){

        if(window.gameData&&window.gameData.fightItem){
            for(var i=0;i<window.gameData.fightItem.length;i++){

                if(window.gameData.fightItem[i].type == itemName){
                    if(window.gameData.fightItem[i].nmb){
                        return window.gameData.fightItem[i].nmb;
                    }else{
                        return 1;
                    }
                }

            }
        }

        return 0;
    },

    getFriendValue:function(npcname){

        var npclog = _GAMEDATAHELPER.getNpcLog(npcname);

        if(
            npclog
        ){

            return npclog.f

        }else{

            return 0;

        }

    },

    getCityCountry(cityName){

        if(
            window.gameData
            &&window.gameData.cityLog
            ){
            return window.gameData.cityLog[cityName];
        }

        return null;

    },


    getTitleOfNpc:function(npcname){

        var  npclog = _GAMEDATAHELPER.getNpcLog(npcname);

        if(
            npclog
        ){
            if(npclog.country!='中立'&&_MASTER[npclog.country]){
                var master = _MASTER[npclog.country];
                var npcconf = _NPC[npcname];
                if(_NPC[npcname].title)
                return master.flag?_HONOUR._TITLE1[npcconf.title]:_HONOUR._TITLE2[npcconf.title];
            }else{
                return '无';
            }

        }
        return "???";

    },


	//npc面板获取所属文字
    getNpcCountry(npcname){

        var npclog = _GAMEDATAHELPER.getNpcLog(npcname);

        if(npclog){
            if(
			npclog.country!='中立'
			&&_MASTER[npclog.country]
			&&!_MASTERHELPER.isCountryOver(npclog.country)
			){
                return npclog.city+"("+_MASTER[npclog.country].name+")";
            }else{
                return npclog.city+"(无势力)";
            }

        }
        return "???";
    },


    //卖出比例
    getSellPer:function(){

        //var darkPer = window.gameData.levelDark/_HONOUR._EXPMAX*0.5;

        var sellper = _GAMEDATAHELPER.getSellPerBySelect();

        return (0.5+sellper).toFixed(2);
    },

    //买入比例
    getBuyPer:function(){

        var brightPer = window.gameData.levelBright/_HONOUR._EXPMAX*0.5;
		
		if(_GAMEDATAHELPER.hasTeamSkill('biancai')){
			return (1-brightPer-0.1).toFixed(2);
		}else{
			return (1-brightPer).toFixed(2);
		}
    },

    getEffectObj:function(type){

        if(
            window.gameData.itemEffect
            &&window.gameData.itemEffect[type]
        ){
            return window.gameData.itemEffect[type];
        }
        return null;

    },

    getEffectItemNmb:function(type){

        var nmb =0;

        for(var i=0;i<window.gameData.fightItem.length;i++){

            var tempitem = window.gameData.fightItem[i];
            var itemconf = _FIGHTITEM[tempitem.type];
            if(itemconf&&itemconf.effect&&itemconf.effect.type==type){
                if(!tempitem.nmb){
                    nmb++;
                }else{
                    nmb+=tempitem.nmb;
                }
            }
        }
        return nmb;
    },

    autoUseEffect:function(type){
        if(
            _GAMEDATAHELPER.isEffectOpen(type)
            &&(
                !window.gameData.itemEffect[type]
                ||window.gameData.itemEffect[type].nmb<=0
            )
        ){

            //console.log('加成耗尽开始自动续杯');

            var index = -1;
            var maxnmb = -1;
            var maxitemconf = null;

            for(var i=0;i<window.gameData.fightItem.length;i++){

                var tempitem = window.gameData.fightItem[i];
                var itemconf = _FIGHTITEM[tempitem.type];
                if(itemconf&&itemconf.effect&&itemconf.effect.type==type){
                    if(maxnmb<itemconf.effect.nmb){
                        maxnmb=itemconf.effect.nmb;
                        maxitemconf=itemconf;
                        index=i;
                    }
                }
            }

            if(index!=-1&&maxnmb!=-1&&maxitemconf){
                _GAMEDATAHELPER.reduceGoods(window.gameData.fightItem,index,1);
                window.gameData.itemEffect[type]={nmb:maxitemconf.effect.nmb,double:maxitemconf.effect.double};
            }

        }
    },

    isEffectOpen:function(type){

        return window.gameData['open_'+type];

    },

    openEffect:function(type){

        if(window.gameData['open_'+type]){
            window.gameData['open_'+type]=false;
        }else{
            window.gameData['open_'+type]=true;
            _GAMEDATAHELPER.autoUseEffect(type);
        }

    },

    getEffectPer:function(type){
        if(
            window.gameData.itemEffect
            &&window.gameData.itemEffect[type]
            &&window.gameData.itemEffect[type].double
            &&window.gameData.itemEffect[type].nmb
        ){
            return window.gameData.itemEffect[type].double;
        }
        return null;
    },

    getExpPer:function(){
        return _GAMEDATAHELPER.getEffectPer('exp');
    },

    getGoldPer:function(){
        return _GAMEDATAHELPER.getEffectPer('gold');
    },

    getDropPer:function(){
        return _GAMEDATAHELPER.getEffectPer('drop');
    },

    getMissFightPer:function(){
        return _GAMEDATAHELPER.getEffectPer('missFight');
    },

    //场景状态消减
    reduceEffect:function(type){

        if(
            window.gameData.itemEffect
            &&window.gameData.itemEffect[type]
        ){
            if(window.gameData.itemEffect[type].nmb>=1){
                window.gameData.itemEffect[type].nmb--;
                _GAMEDATAHELPER.autoUseEffect(type);
            }else{
                window.gameData.itemEffect[type]=null;
            }
        }

    },

    selloutall:function(itemArr){

        var totalnmb = 0;
        var totalprice = 0;
        var sellper = _GAMEDATAHELPER.getSellPer();
        /*
        for(var i=0;i<_GAMEDATAHELPER.itemArrTypeConfig.length;i++){
            var temparr = window.gameData[_GAMEDATAHELPER.itemArrTypeConfig[i]];
            for(var j=0;j<temparr.length;){
                var tmpgoods = temparr[j];
                if(!tmpgoods.isLock){
                    var price = _IOF.getGoodsPrice(tmpgoods);
                    var nmb = tmpgoods.nmb?tmpgoods.nmb:1;
                    totalnmb+=nmb;
                    totalprice+=price*nmb;
                    temparr.splice(j,1);
                }else{
                    j++;
                }

            }
        }
        */

        var temparr = window.gameData[itemArr];
        if(temparr){
            for(var j=0;j<temparr.length;){
                var tmpgoods = temparr[j];
                if(!tmpgoods.isLock){
                    var price = _IOF.getGoodsPrice(tmpgoods);
                    var nmb = tmpgoods.nmb?tmpgoods.nmb:1;
                    totalnmb+=nmb;
                    totalprice+=price*nmb;
                    temparr.splice(j,1);
                }else{
                    j++;
                }
            }
        }

        totalprice=Math.floor(totalprice*sellper);

        _GAMEDATAHELPER.oprMoney(totalprice);

        return '以'+sellper+'的比例共卖出'+totalnmb+'件物品,获得:'+totalprice;
    },


    addExp:function(player,exp,maxlv){
        
        var oldlv = _EXPMANAGER.getLevelByExp(player.exp);
        var realafterlv = oldlv;
        if(oldlv<maxlv){//等级低于等级上限则计算实际获得经验
            player.exp+=exp;
            var afterlv = _EXPMANAGER.getLevelByExp(player.exp);
            if(afterlv>=maxlv){
                player.exp=_EXP[maxlv];
                realafterlv = maxlv;
            }else{
                realafterlv = afterlv;
            }
        }
        return {afterlv:realafterlv};
    },

    //随机任务
    /*
    {npc:'001',
    target:[{type:'测试小兵1',nmb:10,current:2},{type:'测试小兵2',nmb:10,current:1}],
    reward:[{type:"gold",nmb:1000},{type:"测试刀",nmb:1}],
    isDark:1,isHonor:0,level:'SS',type:'fight'},
    {npc:'002',
    target:[{type:'材料1',nmb:10},{type:'材料2',nmb:10}],
    reward:[{type:"gold",nmb:1000},{type:"测试马",nmb:1}],
    isDark:0,isHonor:1,level:'A',type:'item',arr:'materialItem'},
    {npc:'003',
    target:[{type:'材料1',nmb:10},{type:'材料2',nmb:10}],
    reward:[{type:"gold",nmb:1000},{type:"测试鞋",nmb:3}],
    isDark:0,isHonor:1,level:'A',type:'item',arr:'materialItem'},
    */
    randomWork:function(npc,oldtype){

        var npclog = _GAMEDATAHELPER.getNpcLog(npc);
        var npcConf = _NPC[npc];

        if(!npclog||!npcConf){
            return ;
        }

        var npclv = npcConf.lv;
        var city = npclog.city;
        var country = npclog.country;
        var randomPer = Math.random();

        if(oldtype){
            if(oldtype=='fight'){
                randomPer=0.6;
            }else{
                randomPer=0.5;
            }
        }

        //var isHonor = (npc==window.gameData.master);
        var isHonor = (country!='中立')&&(country==window.gameData.country);
        var nmb = (Math.floor(npclv/250)+1)*5;
        var gold = npclv*1000;
        var expnmb = npclv*npclv;
        var tempwork = {
            npc:npc,
            target:[],
            reward:[{type:"exp",nmb:expnmb}],
            isDark:0,
            isHonor:isHonor,
            level:'A',
            type:'fight'
        }

        if(randomPer<0.6){//击杀动物
            tempwork.type = 'fight';
            if(_AREAARMY[city]&&_AREAARMY[city].animals&&_AREAARMY[city].animals.length>0){
                var animals = _AREAARMY[city].animals;
                var tmpanimal = _CU.randomObj(animals);
                if(nmb<5){
                    nmb=5;
                }
                tempwork.target.push({type:tmpanimal,nmb:nmb,current:0,lv:_AREAARMY[city].lv});
                //tempwork.reward.push({type:"exp",nmb:expnmb});
                tempwork.reward.push({type:"gold",nmb:gold});
                return tempwork;
            }
        }else{//材料
            
            if(_AREAARMY[city]&&_AREAARMY[city].animals&&_AREAARMY[city].animals.length>0){
                tempwork.type = 'item';
                tempwork.arr='materialItem';
                var animals = _AREAARMY[city].animals;
                var tmpanimal = _CU.randomObj(animals);
                var droparr = _DROP[tmpanimal];
                if(droparr){
                    var dropm = _CU.randomObj(droparr);
                    var dropnmb = Math.floor(nmb/10);
                    if(dropnmb<=0){
                        dropnmb=1;
                    }

                    if(_EQUIP[dropm]){
                        tempwork.arr='equipItem';
                        dropnmb=1;
                    }

                    tempwork.target.push({type:dropm,nmb:dropnmb});
                    return tempwork;
                }
            }
        }
        
        return null;
    },

    isNpcInTeam:function(npc){

        for(var i=0;i<window.gameData.playerTeam.length;i++){
            if(window.gameData.playerTeam[i].name==npc)
                return true;
        }

        for(var i=0;i<window.gameData.playerTeamBack.length;i++){
            if(window.gameData.playerTeamBack[i].name==npc)
                return true;
        }

        return false;
    },

    zhaomuNpc:function(npc){
        var npclog = _GAMEDATAHELPER.getNpcLog(npc);
        if(npclog){
            npclog.zm = 1;
            _GAMEDATAHELPER.addLevelData('levelBright',10);
            var tmpplayer = _ROF.createRole(npc);
            tmpplayer.equip={};
            if(window.gameData.playerTeam.length<5)
                window.gameData.playerTeam.push(tmpplayer);
            else
                window.gameData.playerTeamBack.push(tmpplayer);
        }
    },

    zhaomuVipNpc:function(npc){
        var tmpplayer = _ROF.createRole(npc);
        tmpplayer.equip={};
        if(window.gameData.playerTeam.length<5)
            window.gameData.playerTeam.push(tmpplayer);
        else
            window.gameData.playerTeamBack.push(tmpplayer);
    },

    //获取队员寄存信息
    getSaveTeam:function(){

        if(window.gameData){

            if(window.gameData.playerTeamSave){

                return window.gameData.playerTeamSave;

            }else{

                window.gameData.playerTeamSave = {
                    max:0,
                    arr:[]
                }

                return window.gameData.playerTeamSave;

            }

        }

        return null;

    }


}